export const qiniu = require("qiniu");
const accessKey = 'klKD7OL-R07Ri91Zr_0xCFE40_bk2BZFdFf4mz3_';
const secretKey = 'htg-of0AgKGM_XDL8PjvUUC7Pf_Q_xpfvuD0nnab';
let option = {
    scope: 'xmplus',
    expires: 100,
    returnBody: '{' +
        '"name": $(fname),' +
        '"size": $(fsize),' +
        '"w": $(imageInfo.width),' +
        '"h": $(imageInfo.height),' +
        '"hash": $(etag)' +
        '"key":"$(key)"' +
        '"scope":"$(scope)"' +
        '}'

};

//基础配置
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
let putPolicy, uploadToken;

export const init = (options: object) => {
    option = Object.assign({}, option, options);
    console.log("初始化", options, option)
    putPolicy = new qiniu.rs.PutPolicy(options);
    uploadToken = putPolicy.uploadToken(mac);
    console.log("config",uploadToken)
    //获取文件信息
    let config = new qiniu.conf.Config();
    config.zone = qiniu.zone.Zone_z0;

    //创建BucketManager对象
    let bucketManager = new qiniu.rs.BucketManager(mac, config);
    return {
        config,
        bucketManager,
        uploadToken
    }
};